package com.feri.fc.listener;

import com.feri.fc.caregiver.service.PhysicianService;
import com.feri.fc.config.RocketMQConfig;
import com.feri.fc.mq.PayCallback;
import com.feri.fc.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 千锋Java,为你而生！
 *
 * @Author: Feri
 * @Date:2024/11/26 14:25
 * @Modified:
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = RocketMQConfig.TOPIC_PAY,consumerGroup = "paycallback")
public class PaycallbackListener implements RocketMQListener<PayCallback> {
    @Resource
    private PhysicianService service;
    @Resource
    private OrderService orderService;
    @Override
    public void onMessage(PayCallback payCallback) {
        log.info("开始处理，支付回调内容，支付类型={}，订单号={}",payCallback.getType(),payCallback.getNo());
        if(payCallback.getOrderType().equals("physician")) {
            service.updatePay(payCallback.getNo(), payCallback.getStatus());
        }else if(payCallback.getOrderType().equals("order")) {
            orderService.updateOrder(payCallback.getNo(), payCallback.getStatus());
        }
        log.info("结束处理，支付回调内容，支付类型={}，订单号={}",payCallback.getType(),payCallback.getNo());
    }
}
